#include <iostream>
#include <vector>

/**
 * P节点
 */
int main(){
    int t;
    std::cin >> t;

    while(t--){

        int n;
        std::cin >> n;

        std::vector<int> degrees(n+1, 0);


        std::vector<int> father(n+1, 0);
        std::vector<std::vector<int>> children(n+1, std::vector<int>());

        for(int i=0; i<n-1;i++){
            int x,y;
            std::cin >> x >> y;

            degrees[x]++;
            degrees[y]++;

            children[x].push_back(y);
            father[y] = x;
        }

        int cnt=0;

        for(int i=1;i < degrees.size(); i++){

            int myDegree = degrees[i];

            if (father[i] != 0 && myDegree < degrees[father[i]]){
                continue;
            }

            bool isP = true;
            for(int j=0; j<children[i].size(); j++){
                if (myDegree < degrees[children[i][j]]){
                    isP = false;
                    break;
                }
            }

            if (isP){
                cnt++;
            }

        }

        std::cout << cnt << "\n";

    }

    return 0;
}